<!DOCTYPE html>
<html><body>
<script src="../../../resources/js-test.js"></script>

<p>When selecting from non-anchor Node to anchor node in ShadowDOM, client should not cause page jump.</p>

<div id="host"></div>
<pre id="console"></pre>

<script>
function mouseMoveTo(element)
{
    var x = element.offsetLeft + element.offsetWidth / 2;
    var y = element.offsetTop + element.offsetHeight / 2;
    eventSender.mouseMoveTo(x, y);
}

var shadowRoot = host.attachShadow({mode: 'open'});
shadowRoot.innerHTML = '<span>select form here</span><a href="javascript:alert(\'FAIL\');">select to here</a>';

var lastClickTarget = null;
host.addEventListener('click', function(e) {
    lastClickTarget = e.target;
});
shadowRoot.lastChild.addEventListener('click', function(e) {
    testFailed('Click event on an anchor element should not be fired.');
}, false);

debug('Selecting from a node to another node in ShadowDOM. This should not start page navigation.');
mouseMoveTo(shadowRoot.firstChild);
eventSender.mouseDown();
mouseMoveTo(shadowRoot.firstChild.nextSibling);
eventSender.mouseUp();
shouldBe('lastClickTarget', 'host');
debug('');

lastClickTarget = null;
debug('Clicking a node in ShadowDOM.');
mouseMoveTo(shadowRoot.firstChild);
eventSender.mouseDown();
eventSender.mouseUp();
shouldBe('lastClickTarget', 'host');
debug('');

</script>

</body></body>
